package mapper;

import Conn.Conn;
import com.alibaba.fastjson.JSONObject;
import model.Test;

import java.security.spec.PSSParameterSpec;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CustomName {
        /*
    类: CustomName
    方法: CustomName
    方法说明:
    main 页面使用
        自定义 name 进行查询
     */
    private static PreparedStatement pstam;
    public JSONObject CustomName(Test test) {
        Conn conn = new Conn();
        JSONObject obj = new JSONObject();
        try{
            List<Map> list = new ArrayList<>();
            pstam = conn.getConn().prepareStatement("select * from test where name = ? and design = 0 order by Id");
            pstam.setString(1,test.getName());
            ResultSet resultSet = pstam.executeQuery();
            while (resultSet.next()){
                Map<String,String> map = new HashMap<>();
                map.put("id",resultSet.getString("ID"));
                map.put("name",resultSet.getString("name"));
                map.put("text",resultSet.getString("text"));
                map.put("data",resultSet.getString("data"));
                list.add(map);
            }
            obj.put("List",list);
            return obj;

        }catch (Exception e){
            e.printStackTrace();
            return null;

        }

    }
}
